home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-12 | 4.5 KB | 118 lines | [TEXT/CCL2] |
- ;
- ; movie-window-with-controller.lisp Wed, 29 Jun, 1994
- ;
- ; A simple QuickTimeª movie player using the Movie Controller component.
- ;
- ; This code requires System 7.0 or later. To be exact, get-movie function
- ; has the dependency. If you use System6, get movie resource in another
- ; way and pass it to make-instance with :movie initarg.
- ;
- ; Masaya UEDA
- ; ueda@shpcs.sharp.co.jp
-
- (defclass movie-window (window)
- ((movie :initarg :movie :accessor movie)
- (mcplay :initform nil :accessor mcplay))
- (:default-initargs :movie nil :color-p t :window-show nil
- :window-type :document :window-title "Movie"))
-
- ; ---
-
- (defun gestalt (selector)
- (rlet ((result :signed-long))
- (if (= (#_gestalt selector result) #$noErr)
- (%get-long result)
- nil)))
-
- (defun error-dialog (message &rest r)
- (catch-cancel
- (apply #'message-dialog
- (concatenate 'string "Error: " message) r)))
-
- (defun check-movie-error (message &rest r)
- (unless (= (#_GetMoviesError) #$noErr)
- (apply #'error-dialog message r)))
-
- (defun init-system ()
- (if (gestalt #$gestaltQuickTime)
- (#_EnterMovies)
- (error-dialog "QuickTime is not installed!")))
-
- (defun get-movie ()
- (rlet ((m :pointer) (movie-res-file :signed-integer) (file-types :SFTypeList)
- (reply :StandardFileReply) (resID :signed-integer 0) (was-changed :boolean))
- (rset file-types (SFTypeList.array 0) "MooV")
- (#_StandardGetFilePreview (%null-ptr) 1 file-types reply)
- (when (rref reply :StandardFileReply.sfGood)
- (#_OpenMovieFile (rref reply :StandardFileReply.sfFile) movie-res-file #$fsRdPerm)
- (unless (check-movie-error "Could not open the file.")
- (unwind-protect
- (progn
- (#_NewMovieFromFile m (%get-word movie-res-file) resID
- (%null-ptr) #$newMovieActive was-changed)
- (unless (check-movie-error "Could not get new moview from the file.")
- (return-from get-movie (%get-ptr m))))
- (#_CloseMovieFile (%get-word movie-res-file))
- (check-movie-error "Could not close the file."))))))
-
- (defmethod setup-movie ((mvwnd movie-window))
- (with-accessors ((movie movie) (mcplay mcplay)) mvwnd
- (rlet ((movie-box :rect) (controller-box :rect))
- (#_GetMovieBox movie movie-box)
- (#_OffsetRect :ptr movie-box :long (make-point (- (rref movie-box :rect.left))
- (- (rref movie-box :rect.top))))
- (#_SetMovieBox movie movie-box)
- (unless (check-movie-error "SetMovieBox failed.")
- (setf mcplay (#_NewMovieController movie
- (rref (wptr mvwnd) :WindowRecord.PortRect)
- #$mcTopLeftMovie))
- (cond ((%null-ptr-p mcplay)
- (error-dialog "Could not get controller for movie with MCNewMovieController.")
- (setf mcplay nil))
- (t (#_MCGetControllerBoundsRect mcplay controller-box)
- (unless (check-movie-error "Could not get controller bounds rect.")
- (#_UnionRect movie-box controller-box movie-box)
- (set-view-size mvwnd
- (subtract-points (rref movie-box :rect.bottomright)
- (rref movie-box :rect.topleft)))
- (= (#_MCSetControllerPort (mcplay mvwnd) (wptr mvwnd)) #$noErr))))))))
-
- ; ---
-
- (defmethod initialize-instance :after ((mvwnd movie-window) &rest r)
- (declare (ignore r))
- (when (= (init-system) #$noErr)
- (with-accessors ((movie movie)) mvwnd
- (when (or movie (setf movie (get-movie)))
- (when (setup-movie mvwnd)
- (window-select mvwnd)
- (return-from initialize-instance)))
- (#_ExitMovies)))
- (window-close mvwnd))
-
- (defmethod window-close :after ((mvwnd movie-window))
- (if (movie mvwnd)
- (#_DisposeMovie (movie mvwnd)))
- (if (mcplay mvwnd)
- (#_CloseComponent (mcplay mvwnd)))
- (#_ExitMovies))
-
- (defmethod view-draw-contents :after ((mvwnd movie-window))
- (#_MCDraw (mcplay mvwnd) (wptr mvwnd)))
-
- (defmethod view-click-event-handler :around ((mvwnd movie-window) where)
- (declare (ignore where))
- (if (zerop (#_MCIsPlayerEvent (mcplay mvwnd) *current-event*))
- (call-next-method)))
-
- (defmethod window-null-event-handler :around ((mvwnd movie-window))
- (if (zerop (#_MCIsPlayerEvent (mcplay mvwnd) *current-event*))
- (call-next-method)))
-
- #|
- (make-instance 'movie-window)
-
- (unwind-protect (progn (#_EnterMovies)
- (make-instance 'movie-window :movie (get-movie)))
- (#_ExitMovies))
- |#